﻿using BaseData.DomainLib.AggregatesModel.MaterialAggregate;
using Microsoft.EntityFrameworkCore;
using Swimj.DomainLib.SeedWork;

namespace BaseData.InfrastructureLib.Repositories
{
    public class MaterialRepository : IMaterialRepository
    {
        private readonly BaseDataDbContext _productMaterialDbContext;
        public IUnitOfWork UnitOfWork => _productMaterialDbContext;

        public MaterialRepository(BaseDataDbContext productMaterialDbContext)
        {
            _productMaterialDbContext = productMaterialDbContext;
        }

        public Material Add(Material material)
        {
            return _productMaterialDbContext.Materials.Add(material).Entity;
        }

        public async Task<Material?> Get(int id)
        {
            var material = await _productMaterialDbContext.Materials
                .FirstOrDefaultAsync(i => i.Id == id);

            return material;
        }
    }
}